﻿namespace HRM.CORE.CLASS
{
    using System; using Extra.ERP;
    using System.Data;
    using System.Windows.Forms; using Common;

    public class clsOptionPrintTimekeeperTable
    {
        private bool m_IsShowExtraHour;
        private bool m_IsShowNightDutyDay;
        private bool m_IsShowPrivateHour;
        private int m_Theme;

        public clsOptionPrintTimekeeperTable()
        {
            try
            {
                this.m_Theme = int.Parse(CheckOption("Theme"));
                this.m_IsShowNightDutyDay = bool.Parse(CheckOption("IsShowNightDutyDay"));
                this.m_IsShowExtraHour = bool.Parse(CheckOption("IsShowExtraHour"));
                this.m_IsShowPrivateHour = bool.Parse(CheckOption("IsShowPrivateHour"));
            }
            catch
            {
                this.m_Theme = 0;
                this.m_IsShowNightDutyDay = false;
                this.m_IsShowExtraHour = false;
                this.m_IsShowPrivateHour = false;
            }
        }

        public static string CheckOption(string FieldName)
        {
            try
            {
                DataSet set = new DataSet();
                set.ReadXml(Application.StartupPath + @"\LayoutControl\xucOptionPrintTimekeeperTable.xml");
                return set.Tables[0].Rows[0][FieldName].ToString();
            }
            catch
            {
                return "";
            }
        }

        public void SaveOption()
        {
            DataSet set = new DataSet();
            using (DataTable table = new DataTable())
            {
                table.Columns.Add("Theme", typeof(int));
                table.Columns.Add("IsShowNightDutyDay", typeof(bool));
                table.Columns.Add("IsShowExtraHour", typeof(bool));
                table.Columns.Add("IsShowPrivateHour", typeof(bool));
                object[] objArray = new object[] { this.m_Theme.ToString(), this.m_IsShowNightDutyDay.ToString(), this.m_IsShowExtraHour.ToString(), this.m_IsShowPrivateHour.ToString() };
                table.Rows.Add(new object[0]);
                table.Rows[0][0] = objArray[0];
                table.Rows[0][1] = objArray[1];
                table.Rows[0][2] = objArray[2];
                table.Rows[0][3] = objArray[3];
                set.Tables.Add(table);
            }
            try
            {
                set.WriteXml(Application.StartupPath + @"\LayoutControl\xucOptionPrintTimekeeperTable.xml");
            }
            catch
            {
            }
        }

        public static void SaveOption(int Theme, bool IsShowNightDutyDay, bool IsShowExtraHour, bool IsShowPrivateHour)
        {
            DataSet set = new DataSet();
            using (DataTable table = new DataTable())
            {
                table.Columns.Add("Theme", typeof(int));
                table.Columns.Add("IsShowNightDutyDay", typeof(bool));
                table.Columns.Add("IsShowExtraHour", typeof(bool));
                table.Columns.Add("IsShowPrivateHour", typeof(bool));
                object[] objArray = new object[] { Theme.ToString(), IsShowNightDutyDay.ToString(), IsShowExtraHour.ToString(), IsShowPrivateHour.ToString() };
                table.Rows.Add(new object[0]);
                table.Rows[0][0] = objArray[0];
                table.Rows[0][1] = objArray[1];
                table.Rows[0][2] = objArray[2];
                table.Rows[0][3] = objArray[3];
                set.Tables.Add(table);
            }
            try
            {
                set.WriteXml(Application.StartupPath + @"\LayoutControl\xucOptionPrintTimekeeperTable.xml");
            }
            catch
            {
            }
        }

        public bool IsShowExtraHour
        {
            get
            {
                return this.m_IsShowExtraHour;
            }
            set
            {
                this.m_IsShowExtraHour = value;
            }
        }

        public bool IsShowNightDutyDay
        {
            get
            {
                return this.m_IsShowNightDutyDay;
            }
            set
            {
                this.m_IsShowNightDutyDay = value;
            }
        }

        public bool IsShowPrivateHour
        {
            get
            {
                return this.m_IsShowPrivateHour;
            }
            set
            {
                this.m_IsShowPrivateHour = value;
            }
        }

        public int Theme
        {
            get
            {
                return this.m_Theme;
            }
            set
            {
                this.m_Theme = value;
            }
        }
    }
}

